package com.zerous.staria.ui;

import com.zerous.framework.ui.*;
import java.util.*;
import android.util.*;
import org.json.*;
import com.google.gson.*;
import com.zerous.framework.*;

public class Layout
{
	public String title;
	public List<UIAttrib> guis;
	
	private Map<String, UIBase> gui = new HashMap<String, UIBase>();
	
	public Layout create(Screen scr, Game ga)
	{
		if(title != null)
		{
			Label t = new Label(scr, ga);
			t.setTitle(title);
			gui.put("Title", t);
		}
		for(UIAttrib attr : guis)
		{
			UIBase ui = null;
			String name = attr.name;
			//String x = attr.x, y = attr.y, w = attr.w, h = attr.h;
			
			switch(attr.kind)
			{
				case "Rect":
					//ui = new Rectangle(new Point(attr.x * Zex.Const.px, attr.y * Zex.Const.px), 
					//				   new Point(Integer.valueOf(attr.w), Integer.valueOf(attr.h)));
					break;
					
				case "Button":
					ui = new Button(attr.x * Zex.Const.px, attr.y * Zex.Const.px, attr.w * Zex.Const.px, attr.h * Zex.Const.px);
					break;
					
				case "CheckBox":
					ui = new CheckBox(attr.x * Zex.Const.px, attr.y * Zex.Const.px, attr.w * Zex.Const.px, attr.h * Zex.Const.px);
					break;
			}	
			
			gui.put(name, ui);
		}
		return this;
	}
	
	public UIBase getUI(String name)
	{
		return gui.get(name);
	}
	
	public void update()
	{
		Iterator i = gui.entrySet().iterator();
		while(i.hasNext())
		{
			((UIBase)((Map.Entry)i.next()).getValue()).update();
		}
	}
	
	public void draw()
	{
		Iterator i = gui.entrySet().iterator();
		while(i.hasNext())
		{
			((UIBase)((Map.Entry)i.next()).getValue()).draw();
		}
	}
}
